package com.crm.services;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.crm.model.jdao.ISalopption;
import com.crm.model.jdao.IcontactH;
import com.crm.model.jdao.Icustomer;
import com.crm.model.jdao.IstaffH;
import com.crm.model.jdao.detailedrequirements;
import com.crm.model.mdao.MBISopp;
import com.crm.model.mdao.detailedrequ;
import com.crm.model.pojo.Contact;
import com.crm.model.pojo.Customer;
import com.crm.model.pojo.Detailedrequirement;
import com.crm.model.pojo.Salesopportunity;

@Service
public class salesopportunityServices {
	@Autowired
	ISalopption iSalopption;
	@Autowired 
	detailedrequirements dede;
	@Autowired
	Icustomer icustomer;
	@Autowired
	IstaffH staff;
	@Autowired
	MBISopp mbis;
	@Autowired
	IcontactH icont;
	@Autowired
	detailedrequ de;
	
	public List<Salesopportunity>  aa(){
		List<Salesopportunity> findAll = (List<Salesopportunity>) iSalopption.findAll();
		return   findAll;
	}
	
	public List<Salesopportunity>  bb() throws ParseException{
	 List<Salesopportunity> findAll = mbis.selectBySalesopportunityAll();
	 	/*for(int i=0;i<findAll.size();i++) {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			String formatDate = df.format(findAll.get(i).getExpecttime());
			System.out.println(formatDate);
			
			
			findAll.get(i).setExpecttime();
			System.out.println(findAll.get(i).getExpecttime());
			//System.out.println("date:"+sdf.parse(formatDate));
			findAll.get(i).setType("9");
			System.out.println(findAll.get(i).getType());
	 		
	 	}*/
	 	
	 	/*for (Salesopportunity salesopportunity : findAll) {
			System.out.println("a:"+salesopportunity.getType());
		}*/
		return   findAll;
	}
	
	public List<Detailedrequirement>  cc() throws ParseException{
		 List<Detailedrequirement> findAll = de.selectByDetailedrequirementAll();
		 for (Detailedrequirement detailedrequirement : findAll) {
			System.out.println(detailedrequirement.getImportancedegree());
		}
			return   findAll;
		}
	
	
	public List<Customer>  selectallkehu(){
		List<Customer> findAll = (List<Customer>) icustomer.findAll();
		return   findAll;
	}
	
	public List<Contact>  selectalllianxiren(){
		List<Contact> selectBycid = icont.selectByall();
		return   selectBycid;
	}
	public List<Salesopportunity>  dsadas(String customer){
		List<Salesopportunity> findByCustomerBean = iSalopption.findByCustomerBean(icustomer.findById("1").get().getCid());
		return   findByCustomerBean;
	}
	
	public void xiugai(Salesopportunity r) {
		System.out.println("aa");
			r.setCustomerBean(icustomer.findById("1").get());
			iSalopption.save(r);
	}
	public void xiugai222(Detailedrequirement r) {
		dede.save(r);
	}
	
	public void adddeat(Detailedrequirement d) {
		
		int detaliid = detaliid();
		 d.setDetaliid(detaliid+"");
		 dede.save(d);
	}
	
	public void addsalopp(Salesopportunity r){
			//主键是自增的
		//查询max编号
		int scid = scid();
		  r.setSalesid(scid+"");
			iSalopption.save(r);
	}
	
	/*public List<Contact> selecttcid(String tcid){
		List<Contact> selectBycid = icont.selectBycid(tcid);
		return selectBycid;
	}*/
	
	
	public int scid() {
		String id = null;
		List<Salesopportunity> aa = mbis.selectBySalesopportunityMaxid();
		   System.out.println("dddd:"+aa);
		  for (Salesopportunity salesopportunity : aa) {
			 id= salesopportunity.getSalesid();
		}
		  int idd=Integer.parseInt(id); 
		  int dddd=idd+1;
		  return dddd;
	}
	public int detaliid() {
		String detaliid = null;
		List<Detailedrequirement> aa = de.selectByDetailedrequirementMaxid();
		   System.out.println("dddd:"+aa);
		  for (Detailedrequirement salesopportunity : aa) {
			  detaliid= salesopportunity.getDetaliid();
		}
		  int idd=Integer.parseInt(detaliid); 
		  int dddd=idd+1;
		  return dddd;
	}
	
	
}
